package com.ailight.smart.gateway.config;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.encrypt.KeyStoreKeyFactory;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.security.KeyPair;

/**
 * @author: 朱海鹏
 * @Package: com.ailight.smart.gateway.config
 * @Project: ai-light
 * @date: 2025/3/21 16:53
 * @description :
 */
@Configuration
@EnableConfigurationProperties(JwtProperties.class)
public class SecurityConfig {
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    // todo 这边待完善
    @Bean
    public KeyPair generateKeyPair(JwtProperties jwtProperties) {
        KeyStoreKeyFactory factory = new KeyStoreKeyFactory(
                jwtProperties.getLocation(),
                jwtProperties.getPassword().toCharArray()
        );
        return factory.getKeyPair(jwtProperties.getAlias(),
                jwtProperties.getPassword().toCharArray());
    }
}
